package networkTraining;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class DataSet implements IDataSet
{
	private static final String INPUT_HEADER = "input_";
	private static final String OUTPUT_HEADER = "output_";

	private Set<String> inputNeuronNames;
	private Set<String> outputNeuronNames;

	private List<String> neuronNameList;
	private List<double[]> dataRowList;

	public DataSet()
	{
		inputNeuronNames = new HashSet<String>();
		outputNeuronNames = new HashSet<String>();
		neuronNameList = new ArrayList<String>();
		dataRowList = new ArrayList<double[]>();
	}

	@Override
	public Set<String> getInputNeuronNames()
	{
		return inputNeuronNames;
	}

	@Override
	public Set<String> getOutputNeuronNames()
	{
		return outputNeuronNames;
	}

	@Override
	public void addNeuronName(String name)
	{
		if (name.startsWith(INPUT_HEADER))
			inputNeuronNames.add(name);
		else if (name.startsWith(OUTPUT_HEADER))
			outputNeuronNames.add(name);

		neuronNameList.add(name);
	}

	@Override
	public List<double[]> getDataRowList()
	{
		return dataRowList;
	}

	@Override
	public void addDataRow(double[] rowValues)
	{
		dataRowList.add(rowValues);
	}

	@Override
	public double getInputValueForRow(String inputName, int row)
	{
		return dataRowList.get(row)[neuronNameList.indexOf(inputName)];
	}

	@Override
	public double getExpectedOutputValueForRow(String outputName, int row)
	{
		return dataRowList.get(row)[neuronNameList.indexOf(outputName)];
	}

	@Override
	public int getDataSetSize()
	{
		return dataRowList.size();
	}

}
